package priv.gitonline.flowable.ui.demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.util.Map;

@Controller
@RequestMapping("/my")
public class MyController {

    @RequestMapping("/process")
    public ModelAndView process(){
        ModelAndView mv=new ModelAndView();
//        mv.setViewName("static/process.html");
        InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("static\\process.html");
        StringBuilder content=new StringBuilder();
        try {
            String line=null;
            InputStreamReader tmpReader=new InputStreamReader(inputStream);
            BufferedReader reader = new BufferedReader(tmpReader);
            while((line=reader.readLine())!=null){
                content.append(line);
            }
            tmpReader.close();
            reader.close();
        }catch (Exception e){

        }finally {

        }
        View v=new View() {
            @Override
            public void render(Map<String, ?> map, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
                httpServletResponse.getWriter().write(content.toString());
            }
        };
        mv.setView(v);
        return mv;
    }
}
